/*    */ package com.wzh.service.ad;
/*    */ 
/*    */ import com.wzh.bean.ad.Adjs;
/*    */ import com.wzh.service.base.DaoSupport;
/*    */ import com.wzh.utils.CommonUtil;
/*    */ import java.io.Serializable;
/*    */ import javax.persistence.EntityManager;
/*    */ import javax.persistence.Query;
/*    */ import javax.servlet.ServletContext;
/*    */ import org.apache.struts2.ServletActionContext;
/*    */ import org.springframework.stereotype.Service;
/*    */ 
/*    */ @Service
/*    */ public class AdjsServiceBean extends DaoSupport<Adjs>
/*    */   implements AdjsService
/*    */ {
/*    */   public boolean isExist(String filename)
/*    */   {
/* 18 */     Query query = this.em.createQuery("select count(o) from Adjs o where o.filename=?1");
/* 19 */     query.setParameter(1, filename);
/*    */ 
/* 21 */     return ((Long)query.getSingleResult()).longValue() > 0L;
/*    */   }
/*    */ 
/*    */   public void save(Adjs entity)
/*    */   {
/* 27 */     String path = "/ads/js/" + entity.getFilename() + ".js";
/* 28 */     entity.setFilepath(path);
/*    */ 
/* 30 */     String realpath = ServletActionContext.getServletContext().getRealPath(path);
/* 31 */     CommonUtil.saveStringToFile(realpath, entity.getContent(), "utf-8");
/* 32 */     super.save(entity);
/*    */   }
/*    */ 
/*    */   public void update(Adjs entity)
/*    */   {
/* 38 */     String path = "/ads/js/" + entity.getFilename() + ".js";
/* 39 */     entity.setFilepath(path);
/*    */ 
/* 41 */     String realpath = ServletActionContext.getServletContext().getRealPath(path);
/* 42 */     CommonUtil.saveStringToFile(realpath, entity.getContent(), "utf-8");
/* 43 */     super.update(entity);
/*    */   }
/*    */ 
/*    */   public void delete(Integer id, String filename)
/*    */   {
/* 49 */     String path = "/ads/js/" + filename + ".js";
/* 50 */     String realpath = ServletActionContext.getServletContext().getRealPath(path);
/* 51 */     CommonUtil.deleteFile(realpath);
/*    */ 
/* 53 */     delete(new Serializable[] { id });
/*    */   }
/*    */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.service.ad.AdjsServiceBean
 * JD-Core Version:    0.6.1
 */